<div class="layui-fluid">
    <div class="layui-row">
        <div class="layui-col-xs12">
            <div class="layui-card">
                <div class="layui-card-body">
                    <div class="layui-card-header">
						<div class="layui-row" id="title-label"></div>
						<!-- <label class="layui-form-label" id="title-label"></label> -->
                    </div>
					
					<div class="layui-card-body">
						<form class="layui-form" action="" accept-charset="UTF-8" method="post" id="base_form"
						      lay-filter="base_form">
						    <input id="at_id" type="hidden" name="id">
						    <div class="layui-form-item">
						        <label class="layui-form-label">标题</label>
						        <div class="layui-input-block">
						            <input type="text" name="typeName" required lay-verify="required" placeholder=""
						                   autocomplete="off" class="layui-input" maxlength="20">
						        </div>
						    </div>
							
							<div class="layui-form-item">
							    <label class="layui-form-label">编号</label>
							    <div class="layui-input-block">
							        <input type="text" name="typeNumber" required lay-verify="required" placeholder=""
							               autocomplete="off" class="layui-input" maxlength="20">
							    </div>
							</div>
							
						    <div class="layui-form-item">
						        <div class="layui-input-block">
						            <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="save">保存</button>
						        </div>
						    </div>
						</form>
					</div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
	
    layui.config({
        base: '/src/js/'
    }).use(['admin', 'jquery', 'mockjs', 'table', 'sidebar', 'form'], function () {
        var $ = layui.jquery,
            admin = layui.admin,
            layer = layui.layer,
            table = layui.table,
            sidebar = layui.sidebar,
            form = layui.form;
		var isAdd = true;
		var id = getUrlParam("id");
		form.render();
		if (id != undefined && id != "") {
			$("#title-label").text('修改新闻分类');
		    $("#at_id").val(id);
		    isAdd = false;
		    httpPost(GET_NEWSTYPE_INFO, {id: id}, function (results) {
		        form.val("base_form", {
		            "typeName": results.typeName,
		            "typeNumber": results.typeNumber
		        });
		    }, function (message) {
		    });
		}else{
			$("#title-label").text('新增新闻分类');
		}
		
		form.on('submit(save)', function (data) {
			// layer.msg("保存成功");
			var url;
			if (isAdd) {
			    url = ADD_NEWSTYPE;
			} else {
			    url = UPDATE_NEWSTYPE;
			}
			var params = data.field;
		    
			
			httpPost(url, params, function (results) {
				if (isObjNull(id)) {
					parent.layer.msg("添加成功");
					window.history.go(-1);
					// window.location.href="javascript:history.go(-1)";
				}else{
					parent.layer.msg("修改成功");
				}
			    
			}, function (message) {
				layer.msg(message);
			});
			
		    return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
		});
		
		form.on('select(showType)', function(data){
		  if(data.value == 1){
			  $("#url-div").show();
		  }else{
			  $("#url-div").hide();
		  }
		}); 
    });


</script>

<style scoped>

</style>
